<?php

namespace Form;

use App\Controller\AbstractController;
use App\Dao\Settings\SettingsTaskTopDao;
use Yj\Form\Elm;

abstract class BaseForm   extends AbstractController implements FormInterface
{

    public function update()
    {
        $id = $this->getValidatorData('id');
        $form = Elm::createForm($this->getRoute($id ? 'edit' : 'add'));

        $form->setRule([
            Elm::number('price', '价钱')->required(),
            Elm::number('num', '数量')->required(),
        ]);

        $id && $form->append(
            Elm::hidden('id', $id)
        );
        $lists = $form->setTitle(($id ? '编辑' : '添加') . '置顶道具')->formData(function () use ($id) {
            $formData = [];
            if ($id) {
                $formData = App(SettingsTaskTopDao::class)->where('id', $id)->first();
            }
            return $formData;
        });
        _SUCCESS(formToData($lists));
    }
}